#include "DispTime.h"

static u8 dtime = 1;    //1ms

void disp_time_init(DispTime *dt) {
    dt->accum_flag = 0;
    dt->disp_time = 0;
    dt->accum_count = 0;
}

void accum_time(DispTime *dt) {
    if (dt->accum_flag == ACCUM_START) {
        dt->accum_count ++;
    } else if (dt->accum_flag == ACCUM_WAIT) {
        dt->accum_count = 0;
    }
}

void accum_set_flag(DispTime *dt, u8 flag) {
    dt->accum_flag = flag;
}

void accum_change_flag(DispTime *dt) {
    if (dt->accum_flag == ACCUM_WAIT) {
        dt->accum_flag = ACCUM_START;
    } else if (dt->accum_flag == ACCUM_START) {
        dt->accum_flag = ACCUM_END;
    } else if (dt->accum_flag == ACCUM_END) {
        dt->accum_flag = ACCUM_WAIT;
    }
}

void get_show_time(DispTime *dt, u32 *min, u32 *sec) {
    u32 temp = dt->accum_count / (1000 / dtime);
    *sec = temp % 60;
    *min = temp / 60;
}
